home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1017 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.0 KB  |  96 lines

  1. Path: lugb.latrobe.edu.au!lux!cs102238
  2. From: cs102238@lux.latrobe.edu.au (Gregary John Boyles )
  3. Newsgroups: alt.msdos.programmer,comp.lang.c
  4. Subject: Some C problems
  5. Date: 10 Jan 1996 13:40:03 GMT
  6. Organization: La Trobe University
  7. Distribution: world
  8. Message-ID: <4d0fjj$eok@lugb.latrobe.edu.au>
  9. NNTP-Posting-Host: lux.latrobe.edu.au
  10.  
  11. PROBLEM 1.
  12. void WriteInFileToOutFile(FILE *InFile,FILE *OutFile,char *InFileName,char *OutFileName,long NumBytes,byte DiskNum)
  13. {
  14.      const word Size=1;
  15.      const word MaxBytes=65535; Produces warning : conversion may lose 
  16.                                 significant bits. Why? 65535 is within the
  17.                                 range for a word (unsigned int)
  18.  
  19.      word NumRead,NumWritten;
  20.      long Index;
  21.      void *BufferPtr;
  22.  
  23.      /* Write the disk number to the first byte of the file. */
  24.      fwrite(&DiskNum,Size,1,OutFile);
  25.      BufferPtr=(void *)malloc(MaxBytes);
  26.      Index=0;
  27.      while (Index<=NumBytes)
  28.      {
  29.  
  30.  
  31. Am I using fread and fwrite correctly or do I need to dereference bufferptr 
  32. when I pass it to these procedures because I am finding that NumRead 
  33. (number of bytes read) != NumWritten (number of bytes written - 0).
  34.  
  35. ******************************************************************************
  36. *                                                                            *
  37. *         NumRead=(fread(BufferPtr,Size,MaxBytes,InFile))*Size;              *
  38. *         if (NumRead==0)                                                    *
  39. *         {                                                                  *
  40. *              strcpy(ErrorMessage,"An error occured while reading from infil*
  41. *              strcat(ErrorMessage,InFileName);                              *
  42. *              strcat(ErrorMessage," - please make sure that this file is not*
  43. *              Error(ErrorMessage);                                          *
  44. *              fclose(OutFile);                                              *
  45. *              fclose(InFile);                                               *
  46. *              exit(1);                                                      *
  47. *         }                                                                  *
  48. *         NumWritten=(fwrite(BufferPtr,Size,NumRead,OutFile))*Size;          *
  49. *         if (NumWritten!=NumRead)                                           *
  50. *         {                                                                  *
  51. *              strcpy(ErrorMessage,"An error occured while writing to outfile*
  52. *              strcat(ErrorMessage,OutFileName);                             *
  53. *              strcat(ErrorMessage," - number of bytes read does not equal th*
  54. *              Error(ErrorMessage);                                          *
  55. *              fclose(OutFile);                                              *
  56. *              fclose(InFile);                                               *
  57. *              exit(1);                                                      *
  58. *         }                                                                  *
  59. ******************************************************************************
  60.  
  61.           Index+=NumRead;
  62.      }
  63. }
  64.  
  65.  
  66.  
  67. With this statement DiskInfo.df_total*DiskInfo.df_sclus*DiskInfo.df_bsec calculated
  68. using my calculator produces the correct drive capacity i.e. 360K however
  69. DriveSize does not contain the correct value i.e. 32000 instead of 360000 (approximate).
  70. Why is this happening? The above fields are of type unsigned.
  71.  
  72. PROBLEM 2.
  73. long DriveSize;
  74. struct dfree DiskInfo;
  75. .
  76. .
  77. .
  78.  
  79. getdfree(DriveNum,&DiskInfo);
  80. DriveSize=DiskInfo.df_total*DiskInfo.df_sclus*DiskInfo.df_bsec;
  81.  
  82. df_total:clusters
  83. df_sclus:sectors/cluster
  84. df_bsec:bytes/sector
  85.  
  86.  
  87. PROBLEM 3.
  88. When I want to output a long int type varaible with printf, it prints out
  89. a garbage value for the variable despite declaring it as a li/ld in the
  90. format string. What am I doing wrong?
  91.  
  92. PROBLEM 4.
  93. How do you use literal constants bigger than words e.g. how would you use
  94. the literal constant 1000000 without getting the 'constant out of range'
  95. warning/error?
  96.